<template>
  <div>
    <div v-if="Object.keys(CommentInfo).length !== 0" class="comment-info">
      <div class="info-header">
        <div class="header-title">用户评价</div>
        <div class="header-more">
          更多
          <i class="arrow-right"></i>
        </div>
      </div>
      <div class="info-user">
        <img :src="CommentInfo.user.avatar" alt />
        <span>{{CommentInfo.user.uname}}</span>
      </div>
      <div class="info-detail">
        <p>{{CommentInfo.content}}</p>
        <div class="info-other">
          <span class="date">{{CommentInfo.created | showDate}}</span>
          <span>{{CommentInfo.style}}</span>
        </div>
        <div class="info-imgs">
          <img :src="item" v-for="(item, index) in CommentInfo.images" :key="index" class="clear-fix" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatDate } from "@/common/utils.js";
export default {
  name: "detailCommentInfo",
  props: {
    CommentInfo: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  filters: {
    showDate: function(value) {
      //服务器返回的时间不会是一个实际的日期，发过来的是一个毫秒数，我们要自己格式化
      //是以时间元年为起点，返回对应的时间戳
      let date = new Date(value * 1000);
      //这里的这个formatDate在很多语言中都内置了，但是js没有，这里是我直接网上复制过来的，看他的源码需要一定的正则知识
      return formatDate(date, "yyyy/MM/dd");
    }
  }
};
</script>

<style>
.comment-info {
  padding: 5px 12px;
  color: #333;
  border-bottom: 5px solid #f2f5f8;
  clear: both;
}

.info-header {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.header-title {
  float: left;
  font-size: 15px;
}

.header-more {
  float: right;
  margin-right: 10px;
  font-size: 13px;
}

.info-user {
  padding: 10px 0 5px;
}

.info-user img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.info-user span {
  position: relative;
  font-size: 15px;
  top: -15px;
  margin-left: 10px;
}

.info-detail {
  padding: 0 5px 15px;
}

.info-detail p {
  font-size: 14px;
  color: #777;
  line-height: 1.5;
}

.info-detail .info-other {
  font-size: 12px;
  color: #999;
  margin-top: 10px;
}

.info-other .date {
  margin-right: 8px;
}

.info-imgs {
  margin-top: 10px;
}

.info-imgs img {
  width: 70px;
  height: 70px;
  margin-right: 5px;
}

.clear-fix{
  
  
  display: block;
  clear:both;

}
</style>